﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project.MVC.DataAccess
{
    public class PictureAccess
    {
        Linq2SQLDataContext dataContext;
        public PictureAccess()
        {
            dataContext = new Linq2SQLDataContext();
        }
        public IQueryable<Picture> GetList()
        {
            return dataContext.Pictures.OrderByDescending(x => x.Id);
        }
        //public void Edit(Product _object)
        //{
        //    var objectDB = dataContext.Products.Where(c => c.Id == _object.Id).SingleOrDefault();
        //    if (objectDB != null)
        //    {
        //        objectDB.Name = _object.Name;
        //        objectDB.ShortDescription = _object.ShortDescription;
        //        objectDB.FullDescription = _object.FullDescription;
        //        objectDB.UpdatedOnUtc = DateTime.Now;
        //        objectDB.CategoryId = _object.CategoryId;
        //    }
        //    dataContext.SubmitChanges();
        //}
        public Picture GetByKey(int id)
        {
            return dataContext.Pictures.Where(c => c.Id == id).SingleOrDefault();
        }
        public void Insert(Picture _object)
        {
            dataContext.Pictures.InsertOnSubmit(_object);
            dataContext.SubmitChanges();
        }
        public void Delete(Picture _object)
        {
            var objectDB = dataContext.Pictures.Where(c => c.Id == _object.Id).SingleOrDefault();
            if (objectDB != null)
            {
                dataContext.Pictures.DeleteOnSubmit(objectDB);
                dataContext.SubmitChanges();
            }
        }
    }
}
